<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"> <style>
	.KEYW {color: #933;}
	.COMM {color: #bbb; font-style: italic;}
	.NUMB {color: #393;}
	.STRN {color: #393;}
	.REGX {color: #339;}
	.line {border-right: 1px dotted #666; color: #666; font-style: normal;}
	</style></head><body><pre><span class='line'>  1</span> <span class="COMM">/*
<span class='line'>  2</span>  * Properties.js
<span class='line'>  3</span>  * 
<span class='line'>  4</span>  * Copyright (c) 2011, OSBI Ltd. All rights reserved.
<span class='line'>  5</span>  *
<span class='line'>  6</span>  * This library is free software; you can redistribute it and/or
<span class='line'>  7</span>  * modify it under the terms of the GNU Lesser General Public
<span class='line'>  8</span>  * License as published by the Free Software Foundation; either
<span class='line'>  9</span>  * version 2.1 of the License, or (at your option) any later version.
<span class='line'> 10</span>  *
<span class='line'> 11</span>  * This library is distributed in the hope that it will be useful,
<span class='line'> 12</span>  * but WITHOUT ANY WARRANTY; without even the implied warranty of
<span class='line'> 13</span>  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
<span class='line'> 14</span>  * Lesser General Public License for more details.
<span class='line'> 15</span>  *
<span class='line'> 16</span>  * You should have received a copy of the GNU Lesser General Public
<span class='line'> 17</span>  * License along with this library; if not, write to the Free Software
<span class='line'> 18</span>  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
<span class='line'> 19</span>  * MA 02110-1301  USA
<span class='line'> 20</span>  */</span><span class="WHIT">
<span class='line'> 21</span> </span><span class="COMM">/**
<span class='line'> 22</span>  * Maintains query properties like non empty and automatic execution
<span class='line'> 23</span>  */</span><span class="WHIT">
<span class='line'> 24</span> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">Properties</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">Backbone.Model.extend</span><span class="PUNC">(</span><span class="PUNC">{</span><span class="WHIT">    
<span class='line'> 25</span>     </span><span class="NAME">initialize</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">args</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">options</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 26</span> </span><span class="WHIT">        </span><span class="COMM">// Keep track of parent query</span><span class="WHIT">
<span class='line'> 27</span> </span><span class="WHIT">        </span><span class="NAME">this.query</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">options.query</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 28</span> </span><span class="WHIT">        
<span class='line'> 29</span>         </span><span class="COMM">// Update properties with defaults from settings</span><span class="WHIT">
<span class='line'> 30</span> </span><span class="WHIT">        </span><span class="NAME">this.properties</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 31</span> </span><span class="WHIT">        </span><span class="NAME">_.extend</span><span class="PUNC">(</span><span class="NAME">this.properties</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">Settings.QUERY_PROPERTIES</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 32</span> </span><span class="WHIT">        </span><span class="NAME">this.update</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 33</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 34</span> </span><span class="WHIT">    
<span class='line'> 35</span>     </span><span class="NAME">toggle</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">key</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 36</span> </span><span class="WHIT">        </span><span class="COMM">// Toggle property</span><span class="WHIT">
<span class='line'> 37</span> </span><span class="WHIT">        </span><span class="NAME">this.properties</span><span class="PUNC">[</span><span class="NAME">key</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.properties</span><span class="PUNC">[</span><span class="NAME">key</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="STRN">'true'</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> 
<span class='line'> 38</span>             </span><span class="STRN">'false'</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'true'</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 39</span> </span><span class="WHIT">        
<span class='line'> 40</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 41</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 42</span> </span><span class="WHIT">    
<span class='line'> 43</span>     </span><span class="NAME">update</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 44</span> </span><span class="WHIT">        </span><span class="COMM">// FIXME - this really sucks</span><span class="WHIT">
<span class='line'> 45</span> </span><span class="WHIT">        </span><span class="COMM">// Why can't we just use the body?</span><span class="WHIT">
<span class='line'> 46</span> </span><span class="WHIT">        </span><span class="NAME">this.attributes</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 47</span> </span><span class="WHIT">            </span><span class="NAME">properties</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">_.template</span><span class="PUNC">(</span><span class="WHIT">
<span class='line'> 48</span> </span><span class="WHIT">                    </span><span class="STRN">"&lt;% _.each(properties, function(property, name) { %>"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT">
<span class='line'> 49</span> </span><span class="WHIT">                    </span><span class="STRN">"&lt;%= name %> &lt;%= property %>\n"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT">
<span class='line'> 50</span> </span><span class="WHIT">                    </span><span class="STRN">"&lt;% }); %>"</span><span class="WHIT">
<span class='line'> 51</span> </span><span class="WHIT">                    </span><span class="PUNC">)</span><span class="PUNC">(</span><span class="PUNC">{</span><span class="WHIT"> </span><span class="NAME">properties</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">this.properties</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 52</span> </span><span class="WHIT">        </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 53</span> </span><span class="WHIT">        </span><span class="NAME">this.save</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 54</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 55</span> </span><span class="WHIT">    
<span class='line'> 56</span>     </span><span class="NAME">parse</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">response</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 57</span> </span><span class="WHIT">        </span><span class="COMM">// FIXME - POST should return properties as well</span><span class="WHIT">
<span class='line'> 58</span> </span><span class="WHIT">        </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">response</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">"object"</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 59</span> </span><span class="WHIT">            </span><span class="NAME">_.extend</span><span class="PUNC">(</span><span class="NAME">this.properties</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">response</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 60</span> </span><span class="WHIT">        </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 61</span> </span><span class="WHIT">        
<span class='line'> 62</span>         </span><span class="NAME">this.query.workspace.trigger</span><span class="PUNC">(</span><span class="STRN">'properties:loaded'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 63</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 64</span> </span><span class="WHIT">    
<span class='line'> 65</span>     </span><span class="NAME">url</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 66</span> </span><span class="WHIT">        </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">encodeURI</span><span class="PUNC">(</span><span class="NAME">this.query.url</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">"/properties"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 67</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 68</span> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 69</span> </span></pre></body></html>